<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ include file="/WEB-INF/decorators/taglibs.jsp"%>
<div class="w1a">
<div class="w2">系統 » 用戶管理</div>    
<form:form modelAttribute="searchForm" id="searchForm" class="form">
	<table width="100%" border="0" cellspacing="0" cellpadding="6" >  
		<tr><td colspan="2" align="center"><h3>用戶一覽表查詢</h3></td></tr>
		<tr>         
			<td align="right" width="45%"><label for="name">姓名：</label></td> 
			<td><form:input size="10" id="name" path="name" /></td>
		</tr>
		<tr>
			<td align="right"><label for="userName">帳號：</label></td>
			<td><form:input size="10" id="userName" path="userName" /></td>
		</tr>
		<tr>
			<td align="right"><label for="userName">角色：</label></td>
			<td>
				<form:select path="role" id="role">
					<form:option label="" value=""/>
					<form:options items="${roleAuth}" itemLabel="authName" itemValue="roleSeq"/>
				</form:select>
			</td>
		</tr>
		<tr>
			<td align="right"><label for="userName">狀態：</label></td>
			<td>
				<form:select path="status" id="status">
					<form:option label="" value=""/>
					<form:option label="關閉" value="0"/>
					<form:option label="開放" value="1"/>
   				</form:select>
			</td>
		</tr>
		<tr>
			<td align="center" colspan="2">     
				<a href="#do" class="easyui-linkbutton" onclick="doSearch()">查詢</a> 
				<a href="#do" class="easyui-linkbutton" onclick="fmClean()">清空</a>
				<sec:authorize ifAnyGranted="admin"> 
					<a href="${appPath}/users/newForm.htm" class="easyui-linkbutton">新增</a>
				</sec:authorize>	
				<!-- <a href="#do" class="easyui-linkbutton" onclick="exp($('#searchForm'))">匯出</a> -->
			</td>
		</tr>
	</table>	
</form:form>
<table id="tt" class="easyui-datagrid" style="height:360px" url="${appPath}/users/list.json"  
	singleSelect="true" striped="true" title="用戶資料" sortable="true" rownumbers="true" pagination="true">  
	<thead>    
    	<tr>   
            <th field="name" width="100" sortable="true">姓名</th>  
            <th field="userName" width="120" sortable="true">帳號</th>
            <th field="deptName" width="120" sortable="true" >部門</th>  
            <th field="role" width="120" sortable="true" formatter="role">角色</th>  
            <th field="status" width="60" sortable="true" formatter="status">狀態</th>  
            <th field="action" width="120" formatter="action">作業</th>  
		</tr>   
	</thead>   
</table>  
</div>
<script>
function action(val,row,ix){ var str = ""; var o = $('#tt').datagrid('getData').rows[ix];
	<sec:authorize ifAnyGranted="admin">
	str = str + "[<a href='${appPath}/users/get.htm?id="+o.usersSeq+"'>修改</a>]"; 
	str = str + "[<a href='#do' onclick=\"doDel('"+o.usersSeq+"');\">刪除</a>]";
	</sec:authorize>
	return str; 
} 
function status(val,row,ix){ if( val == 0 ){ return "關閉"; }else{ return "開放"; } } 

function doDel(id){
	if (confirm('確定刪除')) {
		$.post('${appPath}/users/delete.json', {id:id} ,function(data) { if(data){doSearch();}else{alert('刪除失敗');} });
	}
}
function doSearch(){ var object = {};
	$.each($('#searchForm').serializeArray(), function(i, v) { object[v.name] = v.value; });
	$('#tt').datagrid('load', object ); 
} 
function fmClean(){$("#searchForm").form('reset');}
function exp( formid ){
	formid.form('submit', { url:'${appPath}/users/exp.htm' });
}
function role(val,row,ix){ var s = "";

	$.ajax({url:"${appPath}/roleAuth/getName.json?id="+val+"&m="+Math.random(), 
		 type: "GET",async:false ,dataType:"text", success:function(d){ s = d; } ,
	});	return s;
}
</script>